﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace CXMLStudioIDE.Common
{
    public class UndoManager
    {
        // Fields
        private Stack m_redoStack = new Stack();
        private Stack m_undoStack = new Stack();

        // Methods
        public void AddCommand(UndoCommand cmd)
        {
            this.m_undoStack.Push(cmd);
            this.m_redoStack.Clear();
        }

        public bool CanRedo()
        {
            return (this.m_redoStack.Count != 0);
        }

        public bool CanUndo()
        {
            return (this.m_undoStack.Count != 0);
        }

        public void Redo()
        {
            if (this.CanRedo())
            {
                UndoCommand command = (UndoCommand)this.m_redoStack.Pop();
                command.Redo();
                this.m_undoStack.Push(command);
            }
        }

        public void Undo()
        {
            if (this.CanUndo())
            {
                UndoCommand command = (UndoCommand)this.m_undoStack.Pop();
                command.Undo();
                this.m_redoStack.Push(command);
            }
        }
    }


}
